/* ESP32C3 WiFi Driver Header */

#ifndef __WIFI_H__
#define __WIFI_H__

#include <stdint.h>
#include <stddef.h>

/* WiFi mode */
typedef enum {
    WIFI_MODE_NULL = 0,
    WIFI_MODE_STA = 1,
    WIFI_MODE_AP = 2,
    WIFI_MODE_APSTA = 3
} wifi_mode_t;

/* WiFi authentication mode */
typedef enum {
    WIFI_AUTH_OPEN = 0,
    WIFI_AUTH_WEP,
    WIFI_AUTH_WPA_PSK,
    WIFI_AUTH_WPA2_PSK,
    WIFI_AUTH_WPA_WPA2_PSK,
    WIFI_AUTH_WPA3_PSK,
    WIFI_AUTH_WPA2_WPA3_PSK,
    WIFI_AUTH_MAX
} wifi_auth_mode_t;

/* WiFi status */
typedef enum {
    WIFI_STATUS_IDLE = 0,
    WIFI_STATUS_CONNECTING,
    WIFI_STATUS_CONNECTED,
    WIFI_STATUS_DISCONNECTED,
    WIFI_STATUS_AP_STARTED,
    WIFI_STATUS_AP_STOPPED
} wifi_status_t;

/* WiFi station configuration */
typedef struct {
    char ssid[32];              /* SSID of target AP */
    char password[64];          /* Password of target AP */
    wifi_auth_mode_t authmode;  /* Auth mode of target AP */
    uint8_t channel;            /* Channel of target AP */
    uint8_t bssid[6];           /* BSSID of target AP */
    uint8_t bssid_set;          /* Whether to use BSSID filter */
} wifi_sta_config_t;

/* WiFi AP configuration */
typedef struct {
    char ssid[32];              /* SSID of AP */
    char password[64];          /* Password of AP */
    uint8_t channel;            /* Channel of AP */
    wifi_auth_mode_t authmode;  /* Auth mode of AP */
    uint8_t ssid_hidden;        /* Whether SSID is hidden */
    uint8_t max_connection;     /* Max number of stations allowed to connect */
    uint16_t beacon_interval;   /* Beacon interval in ms */
} wifi_ap_config_t;

/* WiFi configuration */
typedef struct {
    wifi_mode_t mode;           /* WiFi mode */
    wifi_sta_config_t sta;      /* Station configuration */
    wifi_ap_config_t ap;        /* AP configuration */
} wifi_config_t;

/* WiFi event handler */
typedef void (*wifi_event_handler_t)(wifi_status_t status, void *data);

/* WiFi functions */
void wifi_init(void);
int wifi_set_mode(wifi_mode_t mode);
int wifi_sta_connect(wifi_sta_config_t *config);
int wifi_sta_disconnect(void);
int wifi_ap_start(wifi_ap_config_t *config);
int wifi_ap_stop(void);
wifi_status_t wifi_get_status(void);
void wifi_register_event_handler(wifi_event_handler_t handler);

#endif /* __WIFI_H__ */
